﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using APNS.NET;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace APNSUnitTests.given_a_device_token
{
   
    public class when_I_create_a_device_token
    {

        [TestClass]
        public class from_a_string
        {

            [TestMethod]
            public void then_the_device_token_bytes_should_be_read()
            {
                byte[] expectedTokenBytes = new byte[] { 63,88,150,198,48,47,2,248,120,186,40,194,183,21,51,8,204,226,157,5,174,49,65,154,220,125,181,164,206,110,92,22};
                DeviceToken token = "3f5896c6302f02f878ba28c2b7153308cce29d05ae31419adc7db5a4ce6e5c16";
                var tokenBytes = token.ToByteArray();

                for (int i = 0; i < expectedTokenBytes.Length; i++)
                    Assert.AreEqual(expectedTokenBytes[i], tokenBytes[i]);
            }

        }

        [TestClass]
        public class from_a_byte_array
        {

            [TestMethod]
            public void then_the_device_token_bytes_should_be_read()
            {
                byte[] expectedTokenBytes = new byte[] { 63, 88, 150, 198, 48, 47, 2, 248, 120, 186, 40, 194, 183, 21, 51, 8, 204, 226, 157, 5, 174, 49, 65, 154, 220, 125, 181, 164, 206, 110, 92, 22 };
                byte[] tokenBytes = new byte[] { 1,2,3, 63,88,150,198,48,47,2,248,120,186,40,194,183,21,51,8,204,226,157,5,174,49,65,154,220,125,181,164,206,110,92,22};
                DeviceToken token = DeviceToken.FromBytes(tokenBytes, 3);

                var actualTokenBytes = token.ToByteArray();

                for (int i = 0; i < expectedTokenBytes.Length; i++)
                    Assert.AreEqual(expectedTokenBytes[i], actualTokenBytes[i]);
            }

        }
       
    }
}
